\hypertarget{a00069}{}\section{E\+:/knet-\/git/knet/knet/ip\+\_\+filter.c 文件参考}
\label{a00069}\index{E\+:/knet-\/git/knet/knet/ip\+\_\+filter.\+c@{E\+:/knet-\/git/knet/knet/ip\+\_\+filter.\+c}}
{\ttfamily \#include $<$ctype.\+h$>$}\\*
{\ttfamily \#include \char`\"{}ip\+\_\+filter\+\_\+api.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}trie\+\_\+api.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}address.\+h\char`\"{}}\\*
{\ttfamily \#include \char`\"{}channel\+\_\+ref.\+h\char`\"{}}\\*
\subsection*{结构体}
\begin{DoxyCompactItemize}
\item 
struct \hyperlink{a00017}{\+\_\+ip\+\_\+filter\+\_\+t}
\end{DoxyCompactItemize}
\subsection*{函数}
\begin{DoxyCompactItemize}
\item 
char $\ast$ \hyperlink{a00069_ac995e6dca31c96a79f1e774afd3946f6_ac995e6dca31c96a79f1e774afd3946f6}{\+\_\+trim} (char $\ast$ip, int size)
\begin{DoxyCompactList}\small\item\em 去除字符串起始和结束的空白 \end{DoxyCompactList}\item 
int \hyperlink{a00069_a59e99e08e50dba322d5a644387f9b31e_a59e99e08e50dba322d5a644387f9b31e}{\+\_\+ip\+\_\+filter\+\_\+for\+\_\+each\+\_\+func} (const char $\ast$ip, void $\ast$param)
\begin{DoxyCompactList}\small\item\em 遍历函数 \end{DoxyCompactList}\item 
\hyperlink{a00056_a1c0c604eecd86fc8895cf4bbbba566af_a1c0c604eecd86fc8895cf4bbbba566af}{kip\+\_\+filter\+\_\+t} $\ast$ \hyperlink{a00116_ga14e6d1c3709870a082f203c8ba0ca9f4_ga14e6d1c3709870a082f203c8ba0ca9f4}{knet\+\_\+ip\+\_\+filter\+\_\+create} ()
\begin{DoxyCompactList}\small\item\em 建立\+I\+P过滤器 \end{DoxyCompactList}\item 
void \hyperlink{a00116_gae2d8c7b5356b36261f90f59bc49181e1_gae2d8c7b5356b36261f90f59bc49181e1}{knet\+\_\+ip\+\_\+filter\+\_\+destroy} (\hyperlink{a00056_a1c0c604eecd86fc8895cf4bbbba566af_a1c0c604eecd86fc8895cf4bbbba566af}{kip\+\_\+filter\+\_\+t} $\ast$ip\+\_\+filter)
\begin{DoxyCompactList}\small\item\em 销毁\+I\+P过滤器 \end{DoxyCompactList}\item 
int \hyperlink{a00116_ga044a4fc59ee0910af3c2d030e025c536_ga044a4fc59ee0910af3c2d030e025c536}{knet\+\_\+ip\+\_\+filter\+\_\+load\+\_\+file} (\hyperlink{a00056_a1c0c604eecd86fc8895cf4bbbba566af_a1c0c604eecd86fc8895cf4bbbba566af}{kip\+\_\+filter\+\_\+t} $\ast$ip\+\_\+filter, const char $\ast$path)
\begin{DoxyCompactList}\small\item\em 加载\+I\+P过滤文件 \end{DoxyCompactList}\item 
int \hyperlink{a00116_ga271a51fad46aa61d322b6c9da2d5ba1e_ga271a51fad46aa61d322b6c9da2d5ba1e}{knet\+\_\+ip\+\_\+filter\+\_\+add} (\hyperlink{a00056_a1c0c604eecd86fc8895cf4bbbba566af_a1c0c604eecd86fc8895cf4bbbba566af}{kip\+\_\+filter\+\_\+t} $\ast$ip\+\_\+filter, const char $\ast$ip)
\begin{DoxyCompactList}\small\item\em 添加单个\+I\+P \end{DoxyCompactList}\item 
int \hyperlink{a00116_gae03dc5307ec374e375c2313d27dd08ad_gae03dc5307ec374e375c2313d27dd08ad}{knet\+\_\+ip\+\_\+filter\+\_\+remove} (\hyperlink{a00056_a1c0c604eecd86fc8895cf4bbbba566af_a1c0c604eecd86fc8895cf4bbbba566af}{kip\+\_\+filter\+\_\+t} $\ast$ip\+\_\+filter, const char $\ast$ip)
\begin{DoxyCompactList}\small\item\em 删除单个\+I\+P \end{DoxyCompactList}\item 
int \hyperlink{a00116_ga1425a397cc96d8a1cdf32bff3f1fe645_ga1425a397cc96d8a1cdf32bff3f1fe645}{knet\+\_\+ip\+\_\+filter\+\_\+save} (\hyperlink{a00056_a1c0c604eecd86fc8895cf4bbbba566af_a1c0c604eecd86fc8895cf4bbbba566af}{kip\+\_\+filter\+\_\+t} $\ast$ip\+\_\+filter, const char $\ast$path)
\begin{DoxyCompactList}\small\item\em 保存到文件 \end{DoxyCompactList}\item 
int \hyperlink{a00116_ga6d722330898e2a29a8555d711aab8b01_ga6d722330898e2a29a8555d711aab8b01}{knet\+\_\+ip\+\_\+filter\+\_\+check} (\hyperlink{a00056_a1c0c604eecd86fc8895cf4bbbba566af_a1c0c604eecd86fc8895cf4bbbba566af}{kip\+\_\+filter\+\_\+t} $\ast$ip\+\_\+filter, const char $\ast$ip)
\begin{DoxyCompactList}\small\item\em 检查\+I\+P是否被过滤 \end{DoxyCompactList}\item 
int \hyperlink{a00116_gaa42afdd4af32db13227e991ad457f229_gaa42afdd4af32db13227e991ad457f229}{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+address} (\hyperlink{a00056_a1c0c604eecd86fc8895cf4bbbba566af_a1c0c604eecd86fc8895cf4bbbba566af}{kip\+\_\+filter\+\_\+t} $\ast$ip\+\_\+filter, \hyperlink{a00056_a44e99fab0348ec54cfee119ddd9ceed6_a44e99fab0348ec54cfee119ddd9ceed6}{kaddress\+\_\+t} $\ast$address)
\begin{DoxyCompactList}\small\item\em 检查\+I\+P是否被过滤 \end{DoxyCompactList}\item 
int \hyperlink{a00116_gae44a5a6a2fc4cb6e86ae5fda52dff9d6_gae44a5a6a2fc4cb6e86ae5fda52dff9d6}{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+channel} (\hyperlink{a00056_a1c0c604eecd86fc8895cf4bbbba566af_a1c0c604eecd86fc8895cf4bbbba566af}{kip\+\_\+filter\+\_\+t} $\ast$ip\+\_\+filter, \hyperlink{a00056_a3b7e82599367eade261456f60ebe2cd9_a3b7e82599367eade261456f60ebe2cd9}{kchannel\+\_\+ref\+\_\+t} $\ast$channel)
\begin{DoxyCompactList}\small\item\em 检查\+I\+P是否被过滤 \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{函数说明}
\hypertarget{a00069_a59e99e08e50dba322d5a644387f9b31e_a59e99e08e50dba322d5a644387f9b31e}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!\+\_\+ip\+\_\+filter\+\_\+for\+\_\+each\+\_\+func@{\+\_\+ip\+\_\+filter\+\_\+for\+\_\+each\+\_\+func}}
\index{\+\_\+ip\+\_\+filter\+\_\+for\+\_\+each\+\_\+func@{\+\_\+ip\+\_\+filter\+\_\+for\+\_\+each\+\_\+func}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{\+\_\+ip\+\_\+filter\+\_\+for\+\_\+each\+\_\+func}]{\setlength{\rightskip}{0pt plus 5cm}int \+\_\+ip\+\_\+filter\+\_\+for\+\_\+each\+\_\+func (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{ip, }
\item[{void $\ast$}]{param}
\end{DoxyParamCaption}
)}\label{a00069_a59e99e08e50dba322d5a644387f9b31e_a59e99e08e50dba322d5a644387f9b31e}


遍历函数 

\hypertarget{a00069_ac995e6dca31c96a79f1e774afd3946f6_ac995e6dca31c96a79f1e774afd3946f6}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!\+\_\+trim@{\+\_\+trim}}
\index{\+\_\+trim@{\+\_\+trim}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{\+\_\+trim}]{\setlength{\rightskip}{0pt plus 5cm}char $\ast$ \+\_\+trim (
\begin{DoxyParamCaption}
\item[{char $\ast$}]{ip, }
\item[{int}]{size}
\end{DoxyParamCaption}
)}\label{a00069_ac995e6dca31c96a79f1e774afd3946f6_ac995e6dca31c96a79f1e774afd3946f6}


去除字符串起始和结束的空白 


\begin{DoxyParams}{参数}
{\em ip} & I\+P \\
\hline
{\em size} & 字符串长度 \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{返回}
去除空白后字符串新的起止地址 
\end{DoxyReturn}
\hypertarget{a00116_ga271a51fad46aa61d322b6c9da2d5ba1e_ga271a51fad46aa61d322b6c9da2d5ba1e}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!knet\+\_\+ip\+\_\+filter\+\_\+add@{knet\+\_\+ip\+\_\+filter\+\_\+add}}
\index{knet\+\_\+ip\+\_\+filter\+\_\+add@{knet\+\_\+ip\+\_\+filter\+\_\+add}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{knet\+\_\+ip\+\_\+filter\+\_\+add}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+ip\+\_\+filter\+\_\+add (
\begin{DoxyParamCaption}
\item[{{\bf kip\+\_\+filter\+\_\+t} $\ast$}]{ip\+\_\+filter, }
\item[{const char $\ast$}]{ip}
\end{DoxyParamCaption}
)}\label{a00116_ga271a51fad46aa61d322b6c9da2d5ba1e_ga271a51fad46aa61d322b6c9da2d5ba1e}


添加单个\+I\+P 


\begin{DoxyParams}{参数}
{\em ip\+\_\+filter} & kip\+\_\+filter\+\_\+t实例 \\
\hline
{\em ip} & I\+P \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em error\+\_\+ok} & 成功 \\
\hline
{\em 其他} & 失败 \\
\hline
\end{DoxyRetVals}
\hypertarget{a00116_ga6d722330898e2a29a8555d711aab8b01_ga6d722330898e2a29a8555d711aab8b01}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!knet\+\_\+ip\+\_\+filter\+\_\+check@{knet\+\_\+ip\+\_\+filter\+\_\+check}}
\index{knet\+\_\+ip\+\_\+filter\+\_\+check@{knet\+\_\+ip\+\_\+filter\+\_\+check}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{knet\+\_\+ip\+\_\+filter\+\_\+check}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+ip\+\_\+filter\+\_\+check (
\begin{DoxyParamCaption}
\item[{{\bf kip\+\_\+filter\+\_\+t} $\ast$}]{ip\+\_\+filter, }
\item[{const char $\ast$}]{ip}
\end{DoxyParamCaption}
)}\label{a00116_ga6d722330898e2a29a8555d711aab8b01_ga6d722330898e2a29a8555d711aab8b01}


检查\+I\+P是否被过滤 


\begin{DoxyParams}{参数}
{\em ip\+\_\+filter} & kip\+\_\+filter\+\_\+t实例 \\
\hline
{\em ip} & I\+P \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em 0} & 未被过滤 \\
\hline
{\em 其他} & 被过滤 \\
\hline
\end{DoxyRetVals}
\hypertarget{a00116_gaa42afdd4af32db13227e991ad457f229_gaa42afdd4af32db13227e991ad457f229}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+address@{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+address}}
\index{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+address@{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+address}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+address}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+address (
\begin{DoxyParamCaption}
\item[{{\bf kip\+\_\+filter\+\_\+t} $\ast$}]{ip\+\_\+filter, }
\item[{{\bf kaddress\+\_\+t} $\ast$}]{address}
\end{DoxyParamCaption}
)}\label{a00116_gaa42afdd4af32db13227e991ad457f229_gaa42afdd4af32db13227e991ad457f229}


检查\+I\+P是否被过滤 


\begin{DoxyParams}{参数}
{\em ip\+\_\+filter} & kip\+\_\+filter\+\_\+t实例 \\
\hline
{\em address} & 地址 \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em 0} & 未被过滤 \\
\hline
{\em 其他} & 被过滤 \\
\hline
\end{DoxyRetVals}
\hypertarget{a00116_gae44a5a6a2fc4cb6e86ae5fda52dff9d6_gae44a5a6a2fc4cb6e86ae5fda52dff9d6}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+channel@{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+channel}}
\index{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+channel@{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+channel}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+channel}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+ip\+\_\+filter\+\_\+check\+\_\+channel (
\begin{DoxyParamCaption}
\item[{{\bf kip\+\_\+filter\+\_\+t} $\ast$}]{ip\+\_\+filter, }
\item[{{\bf kchannel\+\_\+ref\+\_\+t} $\ast$}]{channel}
\end{DoxyParamCaption}
)}\label{a00116_gae44a5a6a2fc4cb6e86ae5fda52dff9d6_gae44a5a6a2fc4cb6e86ae5fda52dff9d6}


检查\+I\+P是否被过滤 

过滤对端地址(peer address); 
\begin{DoxyParams}{参数}
{\em ip\+\_\+filter} & kip\+\_\+filter\+\_\+t实例 \\
\hline
{\em channel} & kchannel\+\_\+ref\+\_\+t实例 \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em 0} & 未被过滤 \\
\hline
{\em 其他} & 被过滤 \\
\hline
\end{DoxyRetVals}
\hypertarget{a00116_ga14e6d1c3709870a082f203c8ba0ca9f4_ga14e6d1c3709870a082f203c8ba0ca9f4}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!knet\+\_\+ip\+\_\+filter\+\_\+create@{knet\+\_\+ip\+\_\+filter\+\_\+create}}
\index{knet\+\_\+ip\+\_\+filter\+\_\+create@{knet\+\_\+ip\+\_\+filter\+\_\+create}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{knet\+\_\+ip\+\_\+filter\+\_\+create}]{\setlength{\rightskip}{0pt plus 5cm}{\bf kip\+\_\+filter\+\_\+t}$\ast$ knet\+\_\+ip\+\_\+filter\+\_\+create (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}\label{a00116_ga14e6d1c3709870a082f203c8ba0ca9f4_ga14e6d1c3709870a082f203c8ba0ca9f4}


建立\+I\+P过滤器 

\begin{DoxyReturn}{返回}
kip\+\_\+filter\+\_\+t实例 
\end{DoxyReturn}
\hypertarget{a00116_gae2d8c7b5356b36261f90f59bc49181e1_gae2d8c7b5356b36261f90f59bc49181e1}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!knet\+\_\+ip\+\_\+filter\+\_\+destroy@{knet\+\_\+ip\+\_\+filter\+\_\+destroy}}
\index{knet\+\_\+ip\+\_\+filter\+\_\+destroy@{knet\+\_\+ip\+\_\+filter\+\_\+destroy}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{knet\+\_\+ip\+\_\+filter\+\_\+destroy}]{\setlength{\rightskip}{0pt plus 5cm}void knet\+\_\+ip\+\_\+filter\+\_\+destroy (
\begin{DoxyParamCaption}
\item[{{\bf kip\+\_\+filter\+\_\+t} $\ast$}]{ip\+\_\+filter}
\end{DoxyParamCaption}
)}\label{a00116_gae2d8c7b5356b36261f90f59bc49181e1_gae2d8c7b5356b36261f90f59bc49181e1}


销毁\+I\+P过滤器 


\begin{DoxyParams}{参数}
{\em ip\+\_\+filter} & kip\+\_\+filter\+\_\+t实例 \\
\hline
\end{DoxyParams}
\hypertarget{a00116_ga044a4fc59ee0910af3c2d030e025c536_ga044a4fc59ee0910af3c2d030e025c536}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!knet\+\_\+ip\+\_\+filter\+\_\+load\+\_\+file@{knet\+\_\+ip\+\_\+filter\+\_\+load\+\_\+file}}
\index{knet\+\_\+ip\+\_\+filter\+\_\+load\+\_\+file@{knet\+\_\+ip\+\_\+filter\+\_\+load\+\_\+file}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{knet\+\_\+ip\+\_\+filter\+\_\+load\+\_\+file}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+ip\+\_\+filter\+\_\+load\+\_\+file (
\begin{DoxyParamCaption}
\item[{{\bf kip\+\_\+filter\+\_\+t} $\ast$}]{ip\+\_\+filter, }
\item[{const char $\ast$}]{path}
\end{DoxyParamCaption}
)}\label{a00116_ga044a4fc59ee0910af3c2d030e025c536_ga044a4fc59ee0910af3c2d030e025c536}


加载\+I\+P过滤文件 


\begin{DoxyPre}
文件格式为:
[IP]~\newline
[IP]~\newline
......
\end{DoxyPre}
 
\begin{DoxyParams}{参数}
{\em ip\+\_\+filter} & kip\+\_\+filter\+\_\+t实例 \\
\hline
{\em path} & 文件路径 \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em error\+\_\+ok} & 成功 \\
\hline
{\em 其他} & 失败 \\
\hline
\end{DoxyRetVals}
\hypertarget{a00116_gae03dc5307ec374e375c2313d27dd08ad_gae03dc5307ec374e375c2313d27dd08ad}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!knet\+\_\+ip\+\_\+filter\+\_\+remove@{knet\+\_\+ip\+\_\+filter\+\_\+remove}}
\index{knet\+\_\+ip\+\_\+filter\+\_\+remove@{knet\+\_\+ip\+\_\+filter\+\_\+remove}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{knet\+\_\+ip\+\_\+filter\+\_\+remove}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+ip\+\_\+filter\+\_\+remove (
\begin{DoxyParamCaption}
\item[{{\bf kip\+\_\+filter\+\_\+t} $\ast$}]{ip\+\_\+filter, }
\item[{const char $\ast$}]{ip}
\end{DoxyParamCaption}
)}\label{a00116_gae03dc5307ec374e375c2313d27dd08ad_gae03dc5307ec374e375c2313d27dd08ad}


删除单个\+I\+P 


\begin{DoxyParams}{参数}
{\em ip\+\_\+filter} & kip\+\_\+filter\+\_\+t实例 \\
\hline
{\em ip} & I\+P \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em error\+\_\+ok} & 成功 \\
\hline
{\em 其他} & 失败 \\
\hline
\end{DoxyRetVals}
\hypertarget{a00116_ga1425a397cc96d8a1cdf32bff3f1fe645_ga1425a397cc96d8a1cdf32bff3f1fe645}{}\index{ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}!knet\+\_\+ip\+\_\+filter\+\_\+save@{knet\+\_\+ip\+\_\+filter\+\_\+save}}
\index{knet\+\_\+ip\+\_\+filter\+\_\+save@{knet\+\_\+ip\+\_\+filter\+\_\+save}!ip\+\_\+filter.\+c@{ip\+\_\+filter.\+c}}
\subsubsection[{knet\+\_\+ip\+\_\+filter\+\_\+save}]{\setlength{\rightskip}{0pt plus 5cm}int knet\+\_\+ip\+\_\+filter\+\_\+save (
\begin{DoxyParamCaption}
\item[{{\bf kip\+\_\+filter\+\_\+t} $\ast$}]{ip\+\_\+filter, }
\item[{const char $\ast$}]{path}
\end{DoxyParamCaption}
)}\label{a00116_ga1425a397cc96d8a1cdf32bff3f1fe645_ga1425a397cc96d8a1cdf32bff3f1fe645}


保存到文件 


\begin{DoxyParams}{参数}
{\em ip\+\_\+filter} & kip\+\_\+filter\+\_\+t实例 \\
\hline
{\em path} & 文件路径 \\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{返回值}
{\em error\+\_\+ok} & 成功 \\
\hline
{\em 其他} & 失败 \\
\hline
\end{DoxyRetVals}
